package org.ar.gameserver.common.sql;

import java.io.InputStream;
import java.util.Properties;
import javax.sql.DataSource;      
import org.apache.commons.dbcp.BasicDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;      
import org.ar.gameserver.common.util.LogUtils;
     
/**    
 * @author tom    
 * @version 1.0 2009-07-29    
 */     
public class JDBCTemplate {      
     
    private static DataSource dataSource;      
     
    static {
    	InputStream inStream = JDBCTemplate.class.getResourceAsStream("/dbcpconfig.properties");
		Properties pro = new Properties();
		try {
			pro.load(inStream);
			dataSource = BasicDataSourceFactory.createDataSource(pro);
		} catch (Exception e) {
			LogUtils.error(e);
		} finally {
			try {
				if (inStream != null) {
					inStream.close();
				}
			} catch (Exception e2) {
				LogUtils.error(e2);
			}

		}
    }
    
    public static QueryRunner createQueryRunner() {
    	QueryRunner queryRunner = null;
		try {
			queryRunner = new QueryRunner(dataSource);
		} catch (Exception e) {
			LogUtils.error(e);
		} 
		return queryRunner;    
    }
}  